﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PPSMS_DAL;
using PPSMS_Model;

namespace PPSMS_BLL
{
    public class InverterDevices_BLL
    {
        private InverterDevices_DAL _Dal = new();

        /// <summary>
        /// 获取所有逆变器设备的ID
        /// </summary>
        /// <returns></returns>
        public List<long> GetInverterDeviceIds()
        {
            return _Dal.SelectAll().Select(x => x.InverterID).ToList();
        }

        /// <summary>
        /// 获取所有逆变器设备
        /// </summary>
        /// <returns></returns>
        public List<InverterDevices> SelectAllDevices()
        {
            return _Dal.SelectAll();
        }

        /// <summary>
        /// 根据id查询
        /// </summary>
        /// <param name="id">逆变器设备表id</param>
        /// <returns>逆变器设备表对象</returns>
        public InverterDevices GetDeviceById(long id)
        {
            return _Dal.SelectById(id);
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="inverterDevices">逆变器设备表对象</param>
        public void Add(InverterDevices inverterDevices)
        {
            _Dal.Insert(inverterDevices);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids">逆变器设备表id数组</param>
        public void Delete(params long[] ids)
        {
            _Dal.DeleteByIds(ids);
        }

        /// <summary>
        /// 获取数据库中所有的制造商
        /// </summary>
        /// <returns></returns>
        public List<string > Obtain_Manufacturer()
        {
            var list = new List<string>();
            foreach (var item in SelectAllDevices())
            {
                list.Add(item.Manufacturer);
            }
            return list;
        }

        /// <summary>
        /// 获取数据库中所有的型号 
        /// </summary>
        /// <returns></returns>
        public List<string> Obtain_Model()
        {
            var list = new List<string>();
            foreach (var item in SelectAllDevices())
            {
                list.Add(item.Model);
            }
            return list;
        }

        /// <summary>
        /// 根据逆变器型号查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<InverterDevices> SelectByModel(string model)
        {
            var list = new List<InverterDevices>();
            foreach (var item in SelectAllDevices())
            {
                if(item.Model == model)
                {
                    list.Add(item);
                }
            }
            return list;
        }

        /// <summary>
        /// 根据制造商查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<InverterDevices> SelectByManufacturer(string Manufacturer)
        {
            var list = new List<InverterDevices>();
            foreach (var item in SelectAllDevices())
            {
                if (item.Manufacturer == Manufacturer)
                {
                    list.Add(item);
                }
            }
            return list;
        }

        /// <summary>
        /// 根据制造商和逆变器型号查询
        /// </summary>
        /// <param name="manufacturer"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<InverterDevices> SelectByModel_Manufacturer(string manufacturer,string model)
        {
            var list = new List<InverterDevices>();
            foreach (var item in SelectByModel(model))
            {
                if (item.Manufacturer == manufacturer)
                {
                    list.Add(item);
                }
            }
            return list;
        }

        /// <summary>
        /// 根据ID修改逆变器设备表
        /// </summary>
        /// <param name="inverter">修改后的逆变器设备表对象</param>
        /// <param name="id"></param>
        public void UpdateById(InverterDevices inverter ,long id)
        {
            _Dal.UpdateById(inverter, id);
        }
    }
}
